/**
 * 画用户之间的相似度关系图
 */

Ext.onReady(function() {

	/*
	 * require("./js/Chart.js"); require("./js/jquery.timelinr-0.9.6.js");
	 */

//	 drawRelationChart('二狗子', []);
	var calculatedResponseText = '';
	Ext.Ajax.request({

		url : '../servlet/userRelatedRecommend',
		async : true,
		success : function(response) {

			calculatedResponseText = response.responseText;

			calculatedJsonText = JSON.parse(calculatedResponseText);
			var currUserId = calculatedJsonText.currUserId;
			var currUserName = calculatedJsonText.currUserName;
			var historySteps = calculatedJsonText.historySteps;
			var relatedUsers = calculatedJsonText.relatedUsers;
			var recommendedSpots = calculatedJsonText.recommendedSpots;

			// 需要请求数据
			drawHistoryTaste([]);
//			drawRelationChart(currUserName, relatedUsers);
			showPersonalRecommendRestaurant([]);

			// console.log(jsonText);
		},
		failure : function(response) {

			console.log("0000" + response.responseText);

		}

	});

	/*
	 * calculatedJsonText = JSON.parse(calculatedResponseText); var currUserId =
	 * calculatedJsonText.currUserId; var currUserName =
	 * calculatedJsonText.currUserName; var historySteps =
	 * calculatedJsonText.historySteps; var relatedUsers =
	 * calculatedJsonText.relatedUsers; var recommendedSpots =
	 * calculatedJsonText.recommendedSpots;
	 *  // 需要请求数据 drawHistoryTaste(historySteps); drawRelationChart(currUserName,
	 * relatedUsers);
	 */

});


function showPersonalRecommendRestaurant(recommendedSpots){
	
	
	
//	var personalRecommendUl1 = document.getElementById("personalRecommendUl1");
	var personalRecommendUl21 = document.getElementById("personalRecommendUl21");
	var personalRecommendUl22 = document.getElementById("personalRecommendUl22");
	var personalRecommendUl23 = document.getElementById("personalRecommendUl23");
//	var personalRecommendDiv = document.getElementById("personalRecommendDiv");
//	var personalRecommendUl1_li = document.getElementById("personalRecommendUl1_li");
//	var personalRecommendUl1_li_ul1 = document.getElementById("personalRecommendUl1_li_ul1");
//	var personalRecommendUl1_li_ul2 = document.getElementById("personalRecommendUl1_li_ul2");
	
	personalRecommendUl21.innerHTML = '';
	personalRecommendUl22.innerHTML = '';
	personalRecommendUl23.innerHTML = '';
//	personalRecommendUl1_li_ul1.innerHTML = '';
//	personalRecommendUl1_li_ul2.innerHTML = '';
	
//	for(var i=0;i<recommendedSpots.length;i++){
	for(var i=0;i<12;i++){
		
//		if(i<3){//第一行显示的3个景点
//			
//			var elemLi = document.createElement('li');
//			var elemA = document.createElement('a');
//			var elemImg = document.createElement('img');
//			var elemH = document.createElement('h');
//			elemH.className = 'title';
//			elemH.innerHTML = '餐厅' + i;
////			elemH.innerHTML = recommendedSpots[i].spotName;
//			elemImg.src = '../image/default.jpg';
//			
//			elemImg.alt = '餐厅' + i;
////			elemImg.alt = recommendedSpots[i].spotName;
//			
//			elemA.href = '#餐厅' + i;
////			elemA.href = '#' + recommendedSpots[i].spotName;
//			elemA.appendChild(elemImg);
//			elemA.appendChild(elemH);
//			elemLi.appendChild(elemA);
//			personalRecommendUl1_li_ul1.appendChild(elemLi);
//		}else if(3 <= i && i < 6){
//			
//			var elemLi = document.createElement('li');
//			var elemA = document.createElement('a');
//			var elemImg = document.createElement('img');
//			var elemH = document.createElement('h');
//			elemH.className = 'title';
//			elemH.innerHTML = '餐厅' + i;
//			elemImg.src = '../image/default.jpg';
//			elemImg.alt = '餐厅' + i;
//			elemA.href = '#' + '餐厅' + i;
//			elemA.appendChild(elemImg);
//			elemA.appendChild(elemH);
//			elemLi.appendChild(elemA);
//			personalRecommendUl1_li_ul2.appendChild(elemLi);
//		}else{
			
			var elemLi = document.createElement('li');
			
			elemLi.width = '25%';
			var elemA = document.createElement('a');
			var elemImg = document.createElement('img');
			var elemH = document.createElement('h');
			elemH.className = 'title';
			elemH.innerHTML = '餐厅' + (i+1);
			elemImg.src = '../image/default.jpg';
			elemImg.alt ='餐厅' + (i+1);
			elemA.href = '#' + '餐厅' + (i+1);
			elemA.appendChild(elemImg);
			elemA.appendChild(elemH);
			elemLi.appendChild(elemA);
			
			if(i<4){
				personalRecommendUl21.appendChild(elemLi);

			}else if(i >=4 && i < 8){
				personalRecommendUl22.appendChild(elemLi);
			}else
				personalRecommendUl23.appendChild(elemLi);
			
//		}
		
	}
	
}
/**
 * 画脚丫记录足迹
 */
function drawHistoryTaste(historySteps) {

	// <!-- <li><p><a href="#"
	// title='景点1'>2010.01.02</a></p><p>&nbsp;</p><p>&nbsp;</p></li>//创建类似此格式的html内容
	var appendedHtml = '';
	for (var i = 0; i < 10; i++) {

		if (i % 2 == 0) {
			var currHtml = "<li><p><a href=" + '#' + " title='"
					+ '0000-00-00' + "'>"
					+ '祖传周黑鸭百年老店'
					+ "</a></p><p>&nbsp;</p><p>&nbsp;</p></li>";
			appendedHtml += currHtml;
		} else {
			var currHtml = "<li><p>&nbsp;</p><p><a href=" + '#' + " title='"
					+ '0000-00-00' + "'>"
					+ '绝味麻辣川菜馆'
					+ "</a></p><p>&nbsp;</p></li>";
			appendedHtml += currHtml;
		}

	}

	var elemUl1 = document.getElementById('dates');
	elemUl1.innerHTML = appendedHtml;
	/*
	 * var footDiv = document.getElementById("footDiv"); for(var i=0;i<historySteps.length;i++){
	 * 
	 * if(i%2 == 0){
	 * 
	 * var elemUl1 = document.getElementById('footul1');
	 * 
	 * var elemLi1 = document.createElement('li');
	 * 
	 * var elemImg = document.createElement('img'); elemImg.className = 'ouImg';
	 * elemImg.src = './image/foot1.bmp'; elemLi1.appendChild(elemImg);
	 * elemUl1.appendChild(elemLi1);
	 * 
	 * }else{
	 * 
	 * var elemUl1 = document.getElementById('footul1');
	 * 
	 * var elemLi1 = document.createElement('li');
	 * 
	 * var elemImg = document.createElement('img'); elemImg.src =
	 * './image/foot2.bmp'; elemImg.className = 'jiImg';
	 * elemLi1.appendChild(elemImg); elemUl1.appendChild(elemLi1); } }
	 */
}
/*function drawRelationChart(currUserName, related10Users) {

	// 解析参数

	var userNames = new Array();
	var userSims = new Array();

	if (!(related10Users == null || related10Users <= 0)) {

		for (var i = 0; i < related10Users.length; i++) {

			userNames.push(related10Users[i].userName);
			userSims.push(related10Users[i].userSim);
		}
	} else {

		userNames = [ "用啊啊啊啊啊啊啊户1", "用户啊啊啊啊啊啊啊啊啊2", "用啊啊啊啊啊啊啊啊户3", "用户啊啊啊啊啊啊啊4", "用啊啊啊啊啊户5", "用户6啊啊啊啊啊", "用啊啊啊啊啊啊啊户7", "用啊啊啊啊啊啊啊户8",
				"用户9", "用户10" ];
		userSims = [ 0.95, 0.90, 0.75, 0.74, 0.80, 0.66, 0.60, 0.78, 0.33, 0.5 ];

	}

	var ctx = document.getElementById("relaGraph");
	var data = {
		labels : userNames,
		// labels: ["用户1", "用户2", "用户3", "用户4", "用户5", "用户6",
		// "用户7","用户8","用户9","用户10"],
		datasets : [ {
			label : "兴趣偏好相似度",
			backgroundColor : "rgba(255,99,132,0.2)",
			borderColor : "rgba(255,99,132,1)",
			pointBackgroundColor : "rgba(255,99,132,1)",
			pointBorderColor : "#fff",
			pointHoverBackgroundColor : "#fff",
			pointHoverBorderColor : "rgba(255,99,132,1)",
			data : userSims
//			data : [ 0.95, 0.90, 0.75, 0.74, 0.80, 0.66, 0.60, 0.78, 0.33, 0.5 ]
		} ]
	};

	new Chart(ctx, {
		type : "radar",
		data : data,
		options : {
			
//			defaultFontSize:20,
			fontColor: 'rgb(44, 44, 44)',
//			fontSize:20,
//			fullWidth : true

		 scale: { reverse: false, ticks: { beginAtZero: true } }

		}
	});
}*/